import 'package:app_health/pages/regist/WightPage.dart';
import 'package:app_health/utils/ImageUtils.dart';
import 'package:app_health/widget/numberpicker.dart';
import 'package:flutter/material.dart';

/// 选择男女
class SexWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SexWidgetState();
  }
}

class SexWidgetState extends State<SexWidget> {
  /// 默认选中值
  var _isChooseMen = true;
  var _isChooseWomen = false;

  var topText = Column(
    children: <Widget>[
      Container(
        margin: EdgeInsets.only(top: 60.0),
        width: double.infinity,
        alignment: Alignment.center,
        child: Text(
          '欢迎来到倍健康',
          style: TextStyle(fontSize: 18.0),
        ),
      ),
      Container(
        margin: EdgeInsets.only(top: 15.0),
        alignment: Alignment.topCenter,
        width: double.infinity,
        child: Text(
          '请选择你的性别',
          style: TextStyle(fontSize: 15.0, color: Colors.grey),
        ),
      )
    ],
  );

  Widget sexImg() {
    return Container(
      margin: EdgeInsets.only(top: 45.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          GestureDetector(
            onTap: () {
              if (_isChooseMen) return;
              _isChooseMen = true;
              _isChooseWomen = false;
              setState(() {});
            },
            child: Image.asset(_isChooseMen
                ? ImageUtils.getImagePath('men')
                : ImageUtils.getImagePath('men_no_selected')),
          ),
          Container(
            margin: EdgeInsets.only(left: 50.0),
            child: GestureDetector(
              onTap: () {
                if (_isChooseWomen) return;
                _isChooseWomen = true;
                _isChooseMen = false;
                setState(() {});
              },
              child: Image.asset(_isChooseWomen
                  ? ImageUtils.getImagePath('women_selected')
                  : ImageUtils.getImagePath('women')),
            ),
          )
        ],
      ),
    );
  }

  int high = 160;

  Widget showHigh() {
    return Container(
      margin: EdgeInsets.only(top: 40.0),
      child: Row(
        verticalDirection: VerticalDirection.down,
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            high.toString(),
            style: TextStyle(fontSize: 25.0),
          ),
          Text(
            '厘米',
            style: TextStyle(fontSize: 12.0),
          )
        ],
      ),
    );
  }

  /// 请选择你的身高
  var chooseHighTitle = Container(
    margin: EdgeInsets.only(top: 70.0),
    child: Text(
      '请选择你的身高',
      style: TextStyle(fontSize: 18.0),
    ),
  );

  Widget bottom2Btn() {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          //1 上一步
          Expanded(
            child: RaisedButton(
              onPressed: () {},
              splashColor: Color(0xFF0AD0B2),
              color: Color(0xFF0AD0B2),
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(22.0),
                      bottomLeft: Radius.circular(22.0))),
              child: Text(
                '上一步',
                style: TextStyle(color: Color(0xFFe8e8e8)),
              ),
            ),
          ),
          Container(
            width: 1.0,
          ),
          Expanded(
              child: RaisedButton(
            onPressed: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => new WightWidget()));
            },
            splashColor: Color(0xFF0AD0B2),
            color: Color(0xFF0AD0B2),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topRight: Radius.circular(22.0),
                    bottomRight: Radius.circular(22.0))),
            child: Text(
              '下一步',
              style: TextStyle(color: Color(0xFFFFFFFF)),
            ),
          ))
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        iconTheme: IconThemeData(color: Colors.grey),
        //leading: Icon(Icons.arrow_back_ios),
        backgroundColor: Colors.white,
      ),
      body: SingleChildScrollView(
        child:
        Container(
          color: Colors.white,
          child: Column(
            children: <Widget>[
              topText,
              sexImg(),
              chooseHighTitle,
              showHigh(),
              Container(
                margin: EdgeInsets.only(top: 20.0),
                child: NumberPicker.integer(
                    initialValue: high,
                    minValue: 150,
                    maxValue: 300,
                    onChanged: (newValue) {
                      setState(() {
                        high = newValue;
                      });
                    }),
              ),
              bottom2Btn()
            ],
          ),
        ),
      )
    );
  }
}
